"""ETF 数据结构定义."""

from dataclasses import dataclass, field
from datetime import datetime
from typing import Optional

import pandas as pd


@dataclass(frozen=True)
class ETFMetadata:
    """ETF 基础信息."""

    symbol: str = field(metadata={"description": "ETF 代码/交易符号"})
    name: Optional[str] = field(default=None, metadata={"description": "ETF 名称"})
    exchange: Optional[str] = field(default=None, metadata={"description": "交易所代码"})
    fund_family: Optional[str] = field(default=None, metadata={"description": "基金家族/管理公司"})
    category: Optional[str] = field(default=None, metadata={"description": "ETF 类别/分类"})
    currency: Optional[str] = field(default=None, metadata={"description": "货币单位"})
    total_assets: Optional[float] = field(default=None, metadata={"description": "总资产规模"})
    shares_outstanding: Optional[int] = field(default=None, metadata={"description": "流通股数"})
    nav_price: Optional[float] = field(default=None, metadata={"description": "净值价格"})
    previous_close: Optional[float] = field(default=None, metadata={"description": "前一交易日收盘价"})
    source: str = field(default="akshare", metadata={"description": "数据来源"})


@dataclass(frozen=True)
class ETFHistoricalDataset:
    """ETF 历史数据集合."""

    symbol: str = field(metadata={"description": "ETF 代码/交易符号"})
    frame: pd.DataFrame = field(metadata={"description": "历史价格数据 DataFrame，包含 OHLCV 等字段"})
    start: datetime = field(metadata={"description": "数据起始日期时间"})
    end: datetime = field(metadata={"description": "数据结束日期时间"})
    count: int = field(metadata={"description": "数据记录数量"})
    metadata: Optional[ETFMetadata] = field(default=None, metadata={"description": "ETF 元数据信息"})
    source: str = field(default="akshare", metadata={"description": "数据来源"})


@dataclass(frozen=True)
class ETFRealtimeQuote:
    """ETF 盘中实时行情."""

    symbol: str = field(metadata={"description": "ETF 代码/交易符号"})
    price: float = field(metadata={"description": "当前价格"})
    as_of: datetime = field(metadata={"description": "价格时间戳"})
    currency: Optional[str] = field(default=None, metadata={"description": "货币单位"})
    volume: Optional[float] = field(default=None, metadata={"description": "成交量"})
    previous_close: Optional[float] = field(default=None, metadata={"description": "前一交易日收盘价"})
    change: Optional[float] = field(default=None, metadata={"description": "价格变动（绝对值）"})
    change_percent: Optional[float] = field(default=None, metadata={"description": "价格变动百分比"})
    source: str = field(default="akshare", metadata={"description": "数据来源"})

